'''
Description: 
Author: 爱酱丶
Date: 2022-07-22 17:49:40
LastEditTime: 2022-07-22 18:01:14
LastEditors: 爱酱丶
'''
import copy
import json


def l3a_check(paths, tiles, l3a_count):
    """
    获得未被处理了L3A的图幅号
    :param paths: L3A文件路径
    :param tiles: 图幅号列表
    :param l3a_count: 每个图幅对应的L3A文件的数量
    :return: 未被处理的L3A数据的图幅号
    """
    tiles_use = []
    for tile in tiles:
        tile_sum = 0
        for path in paths:
            if tile in path:
                tile_sum = tile_sum + 1
        if tile_sum < l3a_count:
            tiles_use.append(copy.deepcopy(tile))
    return tiles_use


def province2tiles(province):
    """
    根据省名和../conf/ChinaMgrs.json文件获取省对应的图幅号
    :param province:省名:'吉林省'
    :return:
    """
    # with open('./conf/ChinaMgrs.json', 'r') as f:
    
    with open('conf\ChinaMgrs.json','r') as file:
        ChinaMgrs = json.load(file)
    # with open('D:\国源科技\CNES_Project\conf\ChinaMgrs.json', 'r',encoding='utf-8') as f:
        # ChinaMgrs = json.load(fp=f)
    tiles = [tile for tile in ChinaMgrs[province]]
    return tiles


def core_province2tiles(province):
    """
    根据省名和../conf/ChinaMgrs.json文件获取省对应的图幅号
    :param province:省名:'吉林省'
    :return:
    """
    with open('../conf/ChinaMgrs.json', 'r') as f:
        ChinaMgrs = json.load(fp=f)
    tiles = [tile for tile in ChinaMgrs[province]]
    return tiles


def province2scenes(province):
    """
    根据省名和../conf/省名.txt 文件获取省对应的landsat的scenes坐标
    :param province:
    :return:
    """
    scenes_file = '../conf/%s.txt' % province
    with open(scenes_file, 'r') as f:
        scenes = f.readlines()
        scenes = [scene.split('\n')[0] for scene in scenes]
    return scenes


def get_sentinel2_l2a_time(l2a_filepath):
    """
    获取l2a文件的日期
    :param l2a_filepath: l2a文件路径
    :return:
    """
    return l2a_filepath[-37:-29]


def get_sentinel2_l1c_time(l1c_filepath):
    """
    获取l1c文件的日期
    :param l1c_filepath: l1c文件路径：/data/jiabing/sentinel_2_load/he_bei_data/1C/50SNG/S2B_MSIL1C_20200315T025539_N0209_R032_T50SNG_20200315T054510.SAFE
    :return:
    """
    return l1c_filepath[-54:-46]

def get_sentinel2_l3a_time(l3a_filepath):
    """
    获取l2a文件的日期
    :param l2a_filepath: l2a文件路径
    :return:
    """
    return l3a_filepath[-37:-29]